# ifndef __GpsProtocol_H_
# define __GpsProtocol_H_

class CComPort;

	//
	// The base class for computer <-> GPS receiver protocol over given COM port.
	//

class CGpsProtocol {
  public:
	// Synchronous. Return true to stop trying.
	bool Run (CComPort * _pPort, size_t _cPort, HANDLE _hStopEvent, HANDLE _hReadyEvent);

	enum Status_t {stNotSure, stSureOK, stSureError};

	//
	// Methods to be overriden by protocol implementors.
	//

	// Append name of the protocol.
	virtual void GetName (string_t & _strName) const = 0;

	// Start data exchange.
	virtual void Start () = 0;
	// Stop data exchange.
	virtual void Stop  () = 0;

	// On data received (may be NULL on timeout). Return false to stop.
	virtual Status_t OnDataReceived (const BYTE * _pData, size_t _cSize) = 0;

	class CStarter {
	  public:
		CStarter (CGpsProtocol * _pProtocol) : m_pProtocol (_pProtocol) {m_pProtocol->Start ();}
		~CStarter () {m_pProtocol->Stop ();}

	  private:
		CGpsProtocol * const m_pProtocol;
	};

  protected:
	CComPort * m_pPort;
	void Init (CComPort * _pPort) {m_pPort = _pPort;}
};

# endif // __GpsProtocol_H_